/**
 * 
 */
package com.wubo.sec.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wubo.common.util.Assert;
import com.wubo.sec.model.ErrorLog;
import com.wubo.sec.service.IErrorLogService;
import com.wubo.spring.hibernate.BaseHibernateDao;

/**
 * @author wubo
 * @CreateDate 2010-8-8
 * @version 1.0.01
 */
@Service
@SuppressWarnings("unchecked")
public class ErrorLogService implements IErrorLogService {
	
	private BaseHibernateDao dao;
	
	public BaseHibernateDao getDao() {
		return dao;
	}
	@Autowired
	public void setDao(BaseHibernateDao dao) {
		this.dao = dao;
	}

	/* (non-Javadoc)
	 * @see com.asc.sf.service.IErrorLogService#save(com.asc.sf.entity.ErrorLog)
	 */
	public void save(ErrorLog log) {
		dao.save(log);
	}
	
	public List<ErrorLog> getSplitPage(int start, int limit, String filter,
				Object[] params) {
		dao.setCacheQueries(true);
		String where = "";
		if(filter != null){
			if(filter.indexOf("where") != -1){
				where = filter;
			}else{
				where = "where "+filter;
			}
		}
		return dao.queryForPage(start, limit, "select l from ErrorLog l "+where, params);
	}
	
	public long getTotal(String filter, Object[] params) {
		String where = "";
		if(filter != null){
			if(filter.indexOf("where") != -1){
				where = filter;
			}else{
				where = "where "+filter;
			}
		}
		Long result = dao.queryForObject("select count(id) from ErrorLog l "+where, params);
		return result;
	}
	
	public void delAll() {
		dao.bulkUpdate("delete from ErrorLog l");
	}
	
	public void del(String ids) {
		Assert.hasText(ids);
		dao.bulkUpdate("delete from ErrorLog l where l.id in ("+ids+")");
	}

	public List<String> listType(String type) {
		return dao.find("select distinct l.type from ErrorLog l where l.type like '%"+type+"%'");
	}
}
